<?php

use hail812\adminlte3\widgets\Menu;
use yii\helpers\Url;
use mdm\admin\components\MenuHelper;

?>
<aside class="main-sidebar sidebar-dark-primary elevation-4">
    <!-- Brand Logo -->
    <a href="<?= Url::home()?>" class="brand-link">
        <img src="/logo.png" alt="<?= Yii::$app->name ?>" class="brand-image" style="opacity: 1">
        <span class="brand-text font-weight-light">&nbsp;</span>
    </a>

    <!-- Sidebar -->
    <div class="sidebar">
        <!-- Sidebar user panel (optional) -->
        <!--<div class="user-panel mt-3 pb-3 mb-3 d-flex">
            <div class="image">
                <img src="<?/*= $assetDir*/?>/img/user2-160x160.jpg" class="img-circle elevation-2" alt="User Image">
            </div>
            <div class="info">
                <a href="#" class="d-block"><?/*= Yii::$app->getUser()->identity->username */?></a>
            </div>
        </div>-->

        <!-- Sidebar Menu -->
        <nav class="mt-2">

            <?php

            $callback = function ($menu) {
                $data = json_decode($menu['data'], true);
                $items = $menu['children'];
                $return = [
                    'label' => $menu['name'],
                    'url' => [$menu['route']],
                ];
                //处理我们的配置
                if ($data) {
                    //visible
                    isset($data['visible']) && $return['visible'] = $data['visible'];
                    //icon
                    isset($data['icon']) && $data['icon'] && $return['icon'] = $data['icon'];
                    //other attribute e.g. class...
                    $return['options'] = $data;
                }
                //没配置图标的显示默认图标
                (!isset($return['icon']) || !$return['icon']) && $return['icon'] = 'dot-circle';
                $items && $return['items'] = $items;
                return $return;
            };

            if (YII_ENV_PROD) {
                $toolMenu = [];
            } else {
                $toolMenu = [
                    ['label' => 'Gii', 'icon' => 'file-code', 'url' => ['/gii'], 'target' => '_blank'],
                    ['label' => 'Debug', 'icon' => 'bug', 'url' => ['/debug'], 'target' => '_blank']
                ];
            }

            // 模板自带效果，可参考，正式界面去掉
            $ps = [];

            $items = array_merge(MenuHelper::getAssignedMenu(Yii::$app->user->id, null, $callback), $toolMenu, $ps);

            echo Menu::widget([
                'items' => $items
            ]);
            ?>
        </nav>
        <!-- /.sidebar-menu -->
    </div>
    <!-- /.sidebar -->
</aside>